﻿<%@ Page Title="" Language="C#" MasterPageFile="~/web/common/admin_common.Master" AutoEventWireup="true" CodeBehind="edit.aspx.cs" Inherits="shop.web.view_admin.goods.edit" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <title>编辑商品</title>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <div class="fly-panel" pad20 style="padding-top: 5px;">
        <div class="layui-form layui-form-pane">
            <div class="layui-tab layui-tab-brief" lay-filter="user">
                <ul class="layui-tab-title">
                    <li class="layui-this">编辑商品</li>
                </ul>
                <div class="layui-form layui-tab-content" id="LAY_ucm" style="padding: 20px 0;">

                    <div class="layui-tab-item layui-show">
                        <form method="post" action="/handler/GoodsHandler.ashx">
                            <input type="hidden" name="method" value="update" />
                            <input type="hidden" name="id" value="<%=goods.Id %>" />
                            <div class="layui-form-item">
                                <label for="L_name" class="layui-form-label">
                                    商品名称</label>
                                <div class="layui-input-inline">
                                    <input type="text" id="L_name" name="name" required lay-verify="required" placeholder="商品名称"
                                        autocomplete="off" class="layui-input" value="<%=goods.Name %>">
                                </div>
                            </div>
                             <div class="layui-form-item">
                                <label for="L_price" class="layui-form-label">
                                   图片
                                </label>
                                <div class="layui-input-inline">
                                    <img src="/web/resource/img<%=goods.Image.ImagePath%>" alt="Alternate Text" />
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label for="L_price" class="layui-form-label">
                                    商品价格</label>
                                <div class="layui-input-inline">
                                    <input type="text" id="L_price" name="price" required lay-verify="required" placeholder="商品价格"
                                        autocomplete="off" class="layui-input" value="<%=goods.Price %>">
                                </div>
                            </div>

                            <div class="layui-form-item layui-form-text">
                                <label class="layui-form-label">请填写描述</label>
                                
                                <div class="layui-input-block">
                                    <textarea placeholder="请输入内容" class="layui-textarea" name="description"><%=goods.Description %></textarea>
                                </div>
                            </div>

                            <div class="layui-inline  layui-form-item">
                                <label class="layui-form-label">
                                    商品类别</label>
                                <div class="layui-input-block catagory">

                                    <select lay-verify="required" name="catagoryId">
                                        <option></option>
                                        <%foreach (var catagory in catagoryList)
                                            {
                                                if (catagory.Id == goods.CategoryId)
                                                {
                                        %>
                                        <option value="<%=catagory.Id %>" selected><%=catagory.Name %></option>
                                        <%
                                            }else{                                                                                     
                                        %>
                                        <option value="<%=catagory.Id %>"><%=catagory.Name %></option>
                                        <%
                                                }

                                            }
                                        %>
                                    </select>

                                </div>
                            </div>

                            <div class="layui-form-item">
                            </div>


                        </form>
                        <div id="content">

                                </div>
                        <div class="layui-form-item">
                            <button class="layui-btn update" type="button">
                                立即更新</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

   <script src="/web/resource/wangEditor/wangEditor.min.js"></script>
           
    <script>          

       
        layui.use('form', function () {
            var form = layui.form;
        })


        $(function () {
            //            debugger;
            var E = window.wangEditor;
            var editor = new E("#content");
        })

        $(".update").click(function () {
            $.ajax({
                url: $('form').attr('action'),
                type: "post",
                data: $("form").serialize(),
                success: function (data) {
                    console.log($("form").serialize())

                    console.log(data)
                    var obj = JSON.parse(data);
                    console.log(data)
                    if (obj.ErrorCode === 0) {
                        //成功
                        layer.msg(obj.Message, { icon: 6 }, function () {
                            window.location.href = "/web/view_admin/goods/List.aspx";
                        });

                    } else {
                        layer.msg(obj.Message, { icon: 2 })
                    }
                }
            })
        })

    </script>
</asp:Content>

